<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:tax="http://di.uminho.pt/taxonomy#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    >
    
    
    <xsl:template match="/">
                <rdf:RDF
                                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
                                xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
                                xmlns:tax="http://di.uminho.pt/taxonomy#"
                                xmlns:owl="http://www.w3.org/2002/07/owl#">
                 <xsl:apply-templates mode="node" select="//node"/>
                 </rdf:RDF>
    </xsl:template>
    <xsl:template mode="node" match="node">
        <xsl:choose>
            <xsl:when test="@id">
                <owl:Class rdf:about="{@id}">
                    <rdfs:label><xsl:value-of select="@label"/></rdfs:label>
                    <rdfs:comment ><xsl:value-of select="hasNote"/></rdfs:comment>
                      <xsl:if test="parent::isComposedBy">
                           <rdfs:SubClassOf>
                               <xsl:choose>
                                   <xsl:when test="ancestor::*[2]/@id">
                                       <owl:Class rdf:about="{ancestor::*[2]/@id}"/>
                                   </xsl:when>
                                   <xsl:otherwise>
                                       <owl:Class rdf:about="{generate-id(ancestor::*[2])}"/>
                                   </xsl:otherwise>
                               </xsl:choose>
                           </rdfs:SubClassOf>
                      </xsl:if>
                </owl:Class>
            </xsl:when>
            <xsl:otherwise>
                <owl:Class rdf:about="{generate-id()}">
                    <rdfs:label><xsl:value-of select="@label"/></rdfs:label>
                    <rdfs:comment ><xsl:value-of select="hasNote"/></rdfs:comment>
                    <xsl:if test="parent::isComposedBy">
                        <rdfs:SubClassOf>
                            <xsl:choose>
                                <xsl:when test="ancestor::*[2]/@id">
                                    <owl:Class rdf:about="{ancestor::*[2]/@id}"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <owl:Class rdf:about="{generate-id(ancestor::*[2])}"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </rdfs:SubClassOf>
                    </xsl:if>
                </owl:Class>
            </xsl:otherwise>
        </xsl:choose>      
    </xsl:template>
    

</xsl:stylesheet>
